package com.hc.model.code02.test4;

/**
 * @version v1.0
 * @ClassName: Singleton
 * @Description: 双重锁检查
 * @Author: HC
 */
public class Singleton {

    private Singleton() {}

    // 使用volatile保证有序性和可见性
    private volatile static Singleton instances;

    public static Singleton getInstance() {
        if (instances == null) {
            synchronized (Singleton.class) {
                if (instances == null) {
                    instances = new Singleton();
                }
            }
        }
        return instances;
    }
}
